﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TMIS
{
    public partial class frmReply : frmCommon
    {
        private Guid guid;
        private BLL.Reply bll = new BLL.Reply();
        public frmReply()
        {
            InitializeComponent();
            this.FillComponent();
        }
        public frmReply(Guid guid)
        {
            this.guid = guid;
            InitializeComponent();
            this.FillComponent();
        }
        private void FillComponent()
        {
            Model.Reply rep = bll.Get(guid);
            txtLocation.Text = rep.Location;
            CompleteTime.Text = rep.CompleteDate.ToString();
            ReplyTime.Text = rep.ReplyDate.ToString(); ;
            txtSummary.Text = rep.Summary;
            txtContent.Text = rep.Contents.ToString();
            txtProcess.Text = rep.Process.ToString();
            txtReplyScore.Text = rep.ReplyScore.ToString();
            txtInnovation.Text = rep.Innovation.ToString();
            txtTotalScore.Text = rep.TotalScore.ToString();
            txtLeader.Text = rep.Leader;
            string[] members = new string[]{
                rep.Member1,
                rep.Member2,
                rep.Member3,
                rep.Member4,
                rep.Member5,
                rep.Member6,
                rep.Member7,
                rep.Member8};
            string[] assistans = new string[]{
                rep.Assistant1,
                rep.Assistant2};
            MemberGroup.Columns.Add("成员姓名", "成员姓名");
            MemberGroup.Columns[0].Width = 203;
            foreach (var s in members)
            {

                MemberGroup.Rows.Add(s);
            }
            AssistantGroup.Columns.Add("秘书姓名", "秘书姓名");
            AssistantGroup.Columns[0].Width = 203;
            foreach (var a in assistans)
            {
                AssistantGroup.Rows.Add(a);
            }
            this.Priview();
        }
        private void frmReply_Load(object sender, EventArgs e)
        {
            this.ReportView.RefreshReport();
        }
        public override void Save()
        {
            txtTotalScore.Text = (Convert.ToInt16(txtContent.Text) + Convert.ToInt16(txtProcess.Text) + Convert.ToInt16(txtReplyScore.Text) + Convert.ToInt16(txtInnovation.Text)).ToString(); ;
            Model.Reply rep = new Model.Reply()
            {
                ID = this.guid,
                CompleteDate = Convert.ToDateTime(CompleteTime.Text),
                Location = txtLocation.Text,
                ReplyDate = Convert.ToDateTime(ReplyTime.Text),
                Summary = txtSummary.Text,
                Contents = Convert.ToInt16(txtContent.Text),
                Process = Convert.ToInt16(txtProcess.Text),
                ReplyScore = Convert.ToInt16(txtReplyScore.Text),
                Innovation = Convert.ToInt16(txtInnovation.Text),
                TotalScore = Convert.ToInt16(txtTotalScore.Text),
                Leader = txtLeader.Text,
                Member1 = MemberGroup.Rows[0].Cells[0].Value.ToString(),
                Member2 = MemberGroup.Rows[1].Cells[0].Value.ToString(),
                Member3 = MemberGroup.Rows[2].Cells[0].Value.ToString(),
                Member4 = MemberGroup.Rows[3].Cells[0].Value.ToString(),
                Member5 = MemberGroup.Rows[4].Cells[0].Value.ToString(),
                Member6 = MemberGroup.Rows[5].Cells[0].Value.ToString(),
                Member7 = MemberGroup.Rows[6].Cells[0].Value.ToString(),
                Member8 = MemberGroup.Rows[7].Cells[0].Value.ToString(),
                Assistant1 = AssistantGroup.Rows[0].Cells[0].Value.ToString(),
                Assistant2 = AssistantGroup.Rows[1].Cells[0].Value.ToString()
            };
            bll.Update(rep);
        }
        public override void Priview()
        {
            this.replyTableAdapter.FillByStudentID(this.reportDS.Reply, this.guid);
            this.ReportView.RefreshReport();
        }
    }
}
